package com.xx.springboot.designPattern.StrategyPattern;

/**
 * @author hcg
 * @description 抽象鸭子类
 */
public abstract class Duck {
    /**
     * 飞行行为类
     */
    FlyBehavior flyBehavior;

    /**
     * 声音行为类
     */
    QuackBehavior quackBehavior;

    public void setFlyBehavior(FlyBehavior flyBehavior) {
        this.flyBehavior = flyBehavior;
    }

    public void setQuackBehavior(QuackBehavior quackBehavior) {
        this.quackBehavior = quackBehavior;
    }

    /**
     * 将鸭子本身的飞行方法, 交托给行为类来解决
     */
    public void performFly() {
        flyBehavior.fly();
    }

    public void performQuack() {
        quackBehavior.quack();
    }
}
